Search Results

Search found 13 results on 1 pages for 'textout'.

Page 1/1 | 1 

  • win32: TextOut not being displayed

    - by KaiserJohaan
    Hello again, I recently having my mainwindow write text by using WM_PAINT, but now I realise it was maybe not the best message to do so in, so I'm trying another version; The mainwindow contains a menu, upon clicing a menu item the ID_FILE_PID msg is sent and it builds the 4 new windows aswell as displays text in the mainwindow (paintEditSigns function). The 4 windows works fine but the text dosn't work at all, unless I do it in the main() function as shown... what on earth is this? O_O BTW: I still have no clue why the code-display on StackOverflow keeps looking so wierd when I post, why is this? switch(message) { case WM_COMMAND: switch (LOWORD(wParam)) { case ID_FILE_PID: { HWND hWndButton; HWND hWndEdit; HWND hWndEdit2; HWND hWndDisplay; // drawing the text in mainwindow paintEditSigns(); -- does not do anything here! // adding new windows in the mainwindow hWndButton = CreateWindowEx(0,TEXT("BUTTON"),"Modify",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 170,56,80,30,hWnd,(HMENU)ID_BUTTON,hThisInstance,NULL); hWndEdit = CreateWindowEx(0,RICHEDIT_CLASS,TEXT(""),WS_CHILD | WS_VISIBLE | WS_BORDER, 120,30,80,25,hWnd,(HMENU)ID_EDIT,hThisInstance,NULL); hWndEdit2 = CreateWindowEx(0,RICHEDIT_CLASS,TEXT(""),WS_CHILD | WS_VISIBLE | WS_BORDER, 220,30,80,25,hWnd,(HMENU)ID_EDIT2,hThisInstance,NULL); hWndDisplay = CreateWindowEx(0,TEXT("STATIC"),NULL,WS_CHILD | WS_VISIBLE | WS_BORDER, 0,100,450,140,hWnd,(HMENU)ID_DISPLAY,hThisInstance,NULL); break; } ..... // // Main function // int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; WNDCLASSEX wc; ZeroMemory(&wc, sizeof(WNDCLASSEX)); hThisInstance = hInstance; LoadLibrary("Riched20.dll"); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU); if(!(wc.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_MYICON)))) { HRESULT res = GetLastError(); } wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)COLOR_WINDOW; wc.lpszClassName = TEXT("testcpp"); RegisterClassEx(&wc); hWnd = CreateWindowEx(NULL, wc.lpszClassName, TEXT("test"), WS_OVERLAPPEDWINDOW, 300, 200, 450, 300, NULL, NULL, hInstance, NULL); ShowWindow(hWnd,nCmdShow); //paintEditSigns() -- here it works, but not when in the message part MSG msg; while (GetMessage(&msg, NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } void paintEditSigns() { HFONT hf = createFont(); PAINTSTRUCT ps; HWND hWnd = FindWindow(TEXT("testcpp"),TEXT("test")); HBRUSH hbruzh = CreateSolidBrush(RGB(0,0,0)); HDC hdz = BeginPaint(hWnd,&ps); string s = "Memory Address"; SelectBrush(hdz,hbruzh); SelectFont(hdz,hf); TextOut(hdz,0,100,s.c_str(),s.length()); EndPaint(hWnd,&ps); DeleteObject(hbruzh); UpdateWindow(hWnd); } HFONT createFont() { HDC hdc; long lfHeight; hdc = GetDC(NULL); lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72); ReleaseDC(NULL, hdc); HFONT hf = CreateFont(lfHeight, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, "MS Sans Serif"); return hf; }

    Read the article

  • c++, win 32 , Erase text using TextOut or DrawText [on hold]

    - by XXXXX
    How to erase the inputted character on the window and to write the another one on its place??? Say, for example, d d d d was inputted, I want to redraw it to d j j f I'm trying to do this in the following way: TextOut(hdc,rect.right,rect.top,(LPCWSTR)" ",2); DrawText( hdc, (LPCWSTR)str, -1, &rect, DT_SINGLELINE | DT_NOCLIP ) ; or DrawText( hdc, (LPCWSTR)" ", -1, &rect, DT_SINGLELINE | DT_NOCLIP ) ; DrawText( hdc, (LPCWSTR)str, -1, &rect, DT_SINGLELINE | DT_NOCLIP ) ; Anyway, some characters are redrawn, and in some cases(f, j,i characters) the junks are seen(one character is just drawn on another). I haven't set the SetBkMode to transparent. What to do? Thanks much in advance!!!

    Read the article

  • How to get spacing between characters printed using TextOut ?

    - by life-warrior
    I'm trying to calcuate size of each cell (containing text like "ff" or "a0"), so that 32 cells will fit into window by width. However, charWidth*2 doesn' represent the width of a cell, since it doesn't take spacing between characters in the account. How can I obtain size of a font so that 32 cells each is two chars like "ff" fit exactly into window's client area ? Curier is fixed-width font. RECT rect; ::GetClientRect( hWnd, &rect ); LONG charWidth = (rect.right-rect.left)/BLOCK_SIZE/2-2; int oldMapMode = ::SetMapMode( hdc, MM_TEXT ); HFONT font = CreateFont( charWidth*2, charWidth, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, FF_ROMAN, _T("Courier") ); HGDIOBJ oldFont = ::SelectObject( hdc, font ); for( int i = 0; i < BLOCK_SIZE; ++i ) { CString str; str.Format( _T("%.2x"), (unsigned char)*(g_memAddr+i) ); SIZE size; ::TextOut( hdc, (size.cx+2)*i+1, 1, str, _tcslen((LPCTSTR)str) ); }

    Read the article

  • Using TPrinter in Delphi

    - by Milad
    Hello Experts I don't have any backgrounds in programming and this is my first shot. I wrote a Delphi program that is supposed to print on a result sheet. I work in an institute and we have to establish hundreds of result sheets every 2 months. It's really difficult to do that and different handwritings is also an important issue. My problem is that when i write this code : if PrintDialog.Execute() then begin with MyPrinter do begin MyPrinter.BeginDoc();//Start Printing //Prints First Name MyPrinter.Canvas.TextOut(FirstNameX,FirstNameY,EditFirstName.Text); //Prints Last Name MyPrinter.Canvas.TextOut(LastNameX,LastNameY,EditLastName.Text); //Prints Level MyPrinter.Canvas.TextOut(LevelX,LevelY,EditLevel.Text); //Prints Date MyPrinter.Canvas.TextOut(DateX,DateY,MEditDate.Text); //Prints Student Number MyPrinter.Canvas.TextOut(StdNumX,StdNumY,EditStdnumber.Text); .... MyPrinter.EndDoc();//End Printing end; end; I can't get the right coordinates to print properly. Am I missing something? How can I set the right coordinates? You know TPrinter uses pixels to get the coordinates but papers are measured in inches or centimeters. I'm really confused.I appreciate any help. Thanks in advance.

    Read the article

  • How can I print text fields at the right coordinates?

    - by Milad
    I don't have any background in programming and this is my first shot. I wrote a Delphi program that is supposed to print on a result sheet. I work in an institute and we have to establish hundreds of result sheets every 2 months. It's really difficult to do that and different handwriting is also an important issue. I have this code: if PrintDialog.Execute() then begin with MyPrinter do begin MyPrinter.BeginDoc();//Start Printing //Prints First Name MyPrinter.Canvas.TextOut(FirstNameX,FirstNameY,EditFirstName.Text); //Prints Last Name MyPrinter.Canvas.TextOut(LastNameX,LastNameY,EditLastName.Text); //Prints Level MyPrinter.Canvas.TextOut(LevelX,LevelY,EditLevel.Text); //Prints Date MyPrinter.Canvas.TextOut(DateX,DateY,MEditDate.Text); //Prints Student Number MyPrinter.Canvas.TextOut(StdNumX,StdNumY,EditStdnumber.Text); .... MyPrinter.EndDoc();//End Printing end; end; I can't get the right coordinates to print properly. Am I missing something? How can I set the right coordinates? You know TPrinter uses pixels to get the coordinates but papers are measured in inches or centimeters. I'm really confused. I appreciate any help.

    Read the article

  • Read Text From Windows Form

    - by omghai2u
    I would like, if for no other reason that an academic exercise, to be able to read text written to a form on a Windows Application. The program appears to be written in non-.NET, but in .NET terms, I think you would describe the program as having a Form with a Label and I would like to read the text from that label. I believe I can see that text being written to the screen with the User32!TextOut (and in other areas User32!DrawString) function. However, it would be nice if I didn't have to hook that function to get the information I'm looking for, but instead if I could just read it from the form directly. So, given a handle to a Window, is it possible to read the text that has been written to that window with functions like TextOut and DrawString using some similar API or other clever means? Or am I going about this the wrong way? Should I just hook the function and look for the text in every call and pray? Thanks!

    Read the article

  • What are useful functions for drawing text (MFC)?

    - by kobac
    I'm creating a line chart control, and I need to write (or better say draw) the axis names and axis values. I found DrawText and TextOut functions, but the text they show is flickering and don't know how to set the font and text orientation (I will need vertical text orientation as well as horizontal). Are there any other functions you could recoommend or how to use these stated above and get the results I need? Thanks in advance. Cheers.

    Read the article

  • Win32 -- Object cleanup and global variables

    - by KaiserJohaan
    Hello, I've got a question about global variables and object cleanup in c++. For example, look at the code here; case WM_PAINT: paintText(&hWnd); break; void paintText(HWND* hWnd) { PAINTSTRUCT ps; HBRUSH hbruzh = CreateSolidBrush(RGB(0,0,0)); HDC hdz = BeginPaint(*hWnd,&ps); char s1[] = "Name"; char s2[] = "IP"; SelectBrush(hdz,hbruzh); SelectFont(hdz,hFont); SetBkMode(hdz,TRANSPARENT); TextOut(hdz,3,23,s1,sizeof(s1)); TextOut(hdz,10,53,s2,sizeof(s2)); EndPaint(*hWnd,&ps); DeleteObject(hdz); DeleteObject(hbruzh); // bad? DeleteObject(ps); // bad? } 1)First of all; which objects are good to delete and which ones are NOT good to delete and why? Not 100% sure of this. 2)Since WM_PAINT is called everytime the window is redrawn, would it be better to simply store ps, hdz and hbruzh as global variables instead of re-initializing them everytime? The downside I guess would be tons of global variables in the end _ but performance-wise would it not be less CPU-consuming? I know it won't matter prolly but I'm just aiming for minimalistic as possible for educational purposes. 3) What about libraries that are loaded in? For example: // // Main // int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // initialize vars HWND hWnd; WNDCLASSEX wc; HINSTANCE hlib = LoadLibrary("Riched20.dll"); ThishInstance = hInstance; ZeroMemory(&wc,sizeof(wc)); // set WNDCLASSEX props wc.cbSize = sizeof(WNDCLASSEX); wc.lpfnWndProc = WindowProc; wc.hInstance = ThishInstance; wc.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_MYICON)); wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)COLOR_WINDOW; wc.lpszClassName = TEXT("PimpClient"); RegisterClassEx(&wc); // create main window and display it hWnd = CreateWindowEx(NULL, wc.lpszClassName, TEXT("PimpClient"), 0, 300, 200, 450, 395, NULL, NULL, hInstance, NULL); createWindows(&hWnd); ShowWindow(hWnd,nCmdShow); // loop message queue MSG msg; while (GetMessage(&msg, NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } // cleanup? FreeLibrary(hlib); return msg.wParam; } 3cont) is there a reason to FreeLibrary at the end? I mean when the process terminates all resources are freed anyway? And since the library is used to paint text throughout the program, why would I want to free before that? Cheers

    Read the article

  • MS Detours Library, detouring non win api function

    - by flavour404
    Hi, I want to use the windows detours library to detour a non win api function. The function is part of the Qt library (QtGui4.dll). I am wondering how I would set up the function signature for : void QPainter::drawText ( const QPointF & position, const QString & text ) I had a go with this and it received my usual share of errors, a little explanation of requirements would be interesting as well: void (QPainter * real_drawText)(const QPointF & position, const QString & text) = drawText This is what they look like for TextOut, under the windows API: BOOL (WINAPI * Real_TextOut)(HDC a0, int a1, int a2, LPCWSTR a3, int a4) = TextOutW; BOOL WINAPI Mine_TextOut(HDC hdc,int X,int Y,LPCWSTR text,int textLen) { BOOL rv = Real_TextOut(hdc, X, Y, text, textLen); HWND hWindow = WindowFromDC(hdc); SendTextMessage(hWindow, text); return rv; } Thanks.

    Read the article

  • Android NDK jni problem

    - by Donal Rafferty
    I have started teaching myself about the Android NDK and I have followed this example here - http://marakana.com/forums/android/android_examples/49.html I have followed the steps perfectly but when I run the application I get the following error: Trying to load lib /data/data/com.cnetworks.ndk/lib/libndk_demo.so 0x435c2d20 Added shared lib /data/data/com.cnetworks.ndk/lib/libndk_demo.so 0x435c2d20 No JNI_OnLoad found in /data/data/com.cnetworks.ndk/lib/libndk_demo.so 0x435c2d20 +++ not scanning '/system/lib/libwebcore.so' for 'hello' (wrong CL) +++ not scanning '/system/lib/libmedia_jni.so' for 'hello' (wrong CL) WARN/dalvikvm(5191): No implementation found for native Lcom/cnetworks/ndk/NativeLib;.hello ()Ljava/lang/String; Here is the java code, nativeLib.hello() is causing the problem. public class NDKdemo2 extends Activity { NativeLib nativeLib; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); nativeLib = new NativeLib(); String helloText = nativeLib.hello(); // Update the UI TextView outText = (TextView) findViewById(R.id.textOut); outText.setText(helloText); } } Has anyone had the same problem before and able to tell me whats wrong?

    Read the article

  • Scripting custom drawing in Delphi application with IF/THEN/ELSE statements?

    - by Jerry Dodge
    I'm building a Delphi application which displays a blueprint of a building, including doors, windows, wiring, lighting, outlets, switches, etc. I have implemented a very lightweight script of my own to call drawing commands to the canvas, which is loaded from a database. For example, one command is ELP 1110,1110,1290,1290,3,8388608 which draws an ellipse, parameters are 1110x1110 to 1290x1290 with pen width of 3 and the color 8388608 converted from an integer to a TColor. What I'm now doing is implementing objects with common drawing routines, and I'd like to use my scripting engine, but this calls for IF/THEN/ELSE statements and such. For example, when I'm drawing a light, if the light is turned on, I'd like to draw it yellow, but if it's off, I'd like to draw it gray. My current scripting engine has no recognition of such statements. It just accepts simple drawing commands which correspond with TCanvas methods. Here's the procedure I've developed (incomplete) for executing a drawing command on a canvas: function DrawCommand(const Cmd: String; var Canvas: TCanvas): Boolean; type TSingleArray = array of Single; var Br: TBrush; Pn: TPen; X: Integer; P: Integer; L: String; Inst: String; T: String; Nums: TSingleArray; begin Result:= False; Br:= Canvas.Brush; Pn:= Canvas.Pen; if Assigned(Canvas) then begin if Length(Cmd) > 5 then begin L:= UpperCase(Cmd); if Pos(' ', L)> 0 then begin Inst:= Copy(L, 1, Pos(' ', L) - 1); Delete(L, 1, Pos(' ', L)); L:= L + ','; SetLength(Nums, 0); X:= 0; while Pos(',', L) > 0 do begin P:= Pos(',', L); T:= Copy(L, 1, P - 1); Delete(L, 1, P); SetLength(Nums, X + 1); Nums[X]:= StrToFloatDef(T, 0); Inc(X); end; Br.Style:= bsClear; Pn.Style:= psSolid; Pn.Color:= clBlack; if Inst = 'LIN' then begin Pn.Width:= Trunc(Nums[4]); if Length(Nums) > 5 then begin Br.Style:= bsSolid; Br.Color:= Trunc(Nums[5]); end; Canvas.MoveTo(Trunc(Nums[0]), Trunc(Nums[1])); Canvas.LineTo(Trunc(Nums[2]), Trunc(Nums[3])); Result:= True; end else if Inst = 'ELP' then begin Pn.Width:= Trunc(Nums[4]); if Length(Nums) > 5 then begin Br.Style:= bsSolid; Br.Color:= Trunc(Nums[5]); end; Canvas.Ellipse(Trunc(Nums[0]),Trunc(Nums[1]),Trunc(Nums[2]),Trunc(Nums[3])); Result:= True; end else if Inst = 'ARC' then begin Pn.Width:= Trunc(Nums[8]); Canvas.Arc(Trunc(Nums[0]),Trunc(Nums[1]),Trunc(Nums[2]),Trunc(Nums[3]), Trunc(Nums[4]),Trunc(Nums[5]),Trunc(Nums[6]),Trunc(Nums[7])); Result:= True; end else if Inst = 'TXT' then begin Canvas.Font.Size:= Trunc(Nums[2]); Br.Style:= bsClear; Pn.Style:= psSolid; T:= Cmd; Delete(T, 1, Pos(' ', T)); Delete(T, 1, Pos(',', T)); Delete(T, 1, Pos(',', T)); Delete(T, 1, Pos(',', T)); Canvas.TextOut(Trunc(Nums[0]), Trunc(Nums[1]), T); Result:= True; end; end else begin //No space found, not a valid command end; end; end; end; What I'd like to know is what's a good lightweight third-party scripting engine I could use to accomplish this? I would hate to implement parsing of IF, THEN, ELSE, END, IFELSE, IFEND, and all those necessary commands. I need simply the ability to tell the scripting engine if certain properties meet certain conditions, it needs to draw the object a certain way. The light example above is only one scenario, but the same solution needs to also be applicable to other scenarios, such as a door being open or closed, locked or unlocked, and draw it a different way accordingly. This needs to be implemented in the object script drawing level. I can't hard-code any of these scripting/drawing rules, the drawing needs to be controlled based on the current state of the object, and I may also wish to draw a light a certain shade or darkness depending on how dimmed the light is.

    Read the article

  • Reuse Client java Socket in a Java Server

    - by user1394983
    I'm devoloping an Java server two control an android online game. It's possible save the client socket of myserversocket.accept() in a variable in Client class? This are very util because this way, server can communicate with client when server wants and no when client contact server. My actual code are: import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; import java.util.UUID; import sal.app.shared.Packet; public class Server { private ArrayList<GameSession> games = new ArrayList<GameSession>(); private ArrayList<Client> pendent_clients = new ArrayList<Client>(); private Packet read_packet= new Packet(); private Packet sent_packet = new Packet(); private Socket clientSocket = null; public static void main(String[] args) throws ClassNotFoundException{ ServerSocket serverSocket = null; //DataInputStream dataInputStream = null; //DataOutputStream dataOutputStream = null; ObjectOutputStream oos=null; ObjectInputStream ois=null; Server myServer = new Server(); try { serverSocket = new ServerSocket(7777); System.out.println("Listening :7777"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } while(true){ try { myServer.clientSocket = new Socket(); myServer.clientSocket = serverSocket.accept(); myServer.read_packet = new Packet(); myServer.sent_packet = new Packet(); oos = new ObjectOutputStream(myServer.clientSocket.getOutputStream()); ois = new ObjectInputStream(myServer.clientSocket.getInputStream()); //dataInputStream = new DataInputStream(clientSocket.getInputStream()); //dataOutputStream = new DataOutputStream(clientSocket.getOutputStream()); //System.out.println("ip: " + clientSocket.getInetAddress()); //System.out.println("message: " + ois.read()); //dataOutputStream.writeUTF("Hello!"); /*while ((myServer.read_packet = (Packet) ois.readObject()) != null) { myServer.handlePacket(myServer.read_packet); break; }*/ myServer.read_packet=(Packet) ois.readObject(); myServer.handlePacket(myServer.read_packet); //oos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ if( myServer.clientSocket!= null){ /*try { //myServer.clientSocket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ } /*if( ois!= null){ try { ois.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if( oos!= null){ try { oos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }*/ } } } public void handlePacket(Packet hp) throws IOException { if(hp.getOpCode() == 1) { registPlayer(hp); } } public void registPlayer(Packet p) throws IOException { Client registClient = new Client(this.clientSocket); this.pendent_clients.add(registClient); if(pendent_clients.size() == 2) { initAGame(); } else { ObjectOutputStream out=null; Packet to_send = new Packet(); to_send.setOpCode(4); out = new ObjectOutputStream(registClient.getClientSocket().getOutputStream()); out.writeObject(to_send); } } public void initAGame() throws IOException { Client c1 = pendent_clients.get(0); Client c2 = pendent_clients.get(1); Packet to_send = new Packet(); ObjectOutputStream out=null; GameSession incomingGame = new GameSession(c1,c2); games.add(incomingGame); to_send.setGameId(incomingGame.getGameId()); to_send.setOpCode(5); out = new ObjectOutputStream(c1.getClientSocket().getOutputStream()); out.writeObject(to_send); out = new ObjectOutputStream(c2.getClientSocket().getOutputStream()); out.writeObject(to_send); pendent_clients.clear(); } public Client getClientById(UUID given_id) { for(GameSession gs: games) { if(gs.getClient1().getClientId().equals(given_id)) { return gs.getClient1(); } else if(gs.getClient2().getClientId().equals(given_id)) { return gs.getClient2(); } } return null; } } With this code i got this erros: java.net.SocketException: Broken pipe at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) at java.net.SocketOutputStream.write(SocketOutputStream.java:136) at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1847) at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1756) at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1257) at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1211) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1395) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1158) at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1547) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:333) at Server.initAGame(Server.java:146) at Server.registPlayer(Server.java:120) at Server.handlePacket(Server.java:106) at Server.main(Server.java:63) This error ocurre when second client connect and server try to send an Packet to previous client 1 in function initGame() in this code: out = new ObjectOutputStream(c1.getClientSocket().getOutputStream()); out.writeObject(to_send); my android code is this: package sal.app; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.Socket; import java.net.UnknownHostException; import sal.app.logic.DataBaseManager; import sal.app.shared.Packet; import android.app.Activity; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; public class MultiPlayerWaitActivity extends Activity{ private DataBaseManager db; public void onCreate(Bundle savedInstanceState) { super.requestWindowFeature(Window.FEATURE_NO_TITLE); super.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanceState); setContentView(R.layout.multiwaitlayout); db=DataBaseManager.getSalDatabase(this); db.teste(); try { db.createDataBase(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Socket socket = null; ObjectOutputStream outputStream = null; ObjectInputStream inputStream = null; //System.out.println("dadadad"); try { socket = new Socket("192.168.1.4", 7777); //Game = new MultiPlayerGame(new ServerManager("192.168.1.66"),new Session(), new Player("")); outputStream = new ObjectOutputStream(socket.getOutputStream()); inputStream = new ObjectInputStream(socket.getInputStream()); //dataOutputStream.writeUTF(textOut.getText().toString()); //textIn.setText(dataInputStream.readUTF()); Packet p = new Packet(); Packet r = new Packet(); p.setOpCode(1); outputStream.writeObject(p); /*try { r=(Packet)inputStream.readObject(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ //while(true){ //dataInputStream = new DataInputStream(clientSocket.getInputStream()); //dataOutputStream = new DataOutputStream(clientSocket.getOutputStream()); //System.out.println("ip: " + clientSocket.getInetAddress()); //System.out.println("message: " + ois.read()); //dataOutputStream.writeUTF("Hello!"); /*while ((r= (Packet) inputStream.readObject()) != null) { handPacket(r); break; }*/ r=(Packet) inputStream.readObject(); handPacket(r); //oos.close(); //} /*System.out.println(r.getOpCode()); if(r.getOpCode() == 5) { this.finish(); }*/ } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } /*finally{ if (socket != null){ try { socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (outputStream != null){ try { outputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (inputStream != null){ try { inputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }*/ //catch (ClassNotFoundException e) { // TODO Auto-generated catch block //e.printStackTrace(); //} catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void handPacket(Packet hp) { if(hp.getOpCode() == 5) { this.finish(); } this.finish(); } } Regards

    Read the article

1