Click here to Skip to main content
15,880,905 members
Home / Discussions / C#
   

C#

 
QuestionSocket programming Pin
mohammadkaab9-Jan-13 3:32
mohammadkaab9-Jan-13 3:32 
AnswerRe: Socket programming Pin
Dave Kreskowiak9-Jan-13 3:38
mveDave Kreskowiak9-Jan-13 3:38 
GeneralRe: Socket programming Pin
mohammadkaab9-Jan-13 7:13
mohammadkaab9-Jan-13 7:13 
GeneralRe: Socket programming Pin
Dave Kreskowiak9-Jan-13 9:02
mveDave Kreskowiak9-Jan-13 9:02 
GeneralRe: Socket programming Pin
mohammadkaab9-Jan-13 9:25
mohammadkaab9-Jan-13 9:25 
GeneralRe: Socket programming Pin
Dave Kreskowiak10-Jan-13 2:11
mveDave Kreskowiak10-Jan-13 2:11 
AnswerRe: Socket programming Pin
Keith Barrow9-Jan-13 4:15
professionalKeith Barrow9-Jan-13 4:15 
GeneralRe: Socket programming Pin
mohammadkaab9-Jan-13 10:29
mohammadkaab9-Jan-13 10:29 
the code that im using in the server side is like this
C#
Thread thr;
 
Socket Soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        IPEndPoint ipend = new IPEndPoint(IPAddress.Any, 8000);
 
private void buttonX1_Click(object sender, EventArgs e)
        {
            thr = new Thread(Listen);
            thr.Start();   
        }
 
 void Listen()
        {
            Soc.Bind(ipend);
            Soc.Listen(10);
            
            byte[] data = new byte[500];
            while (true)
            {
                // Accept the connection
                Socket client = Soc.Accept();
                client.Receive(data);
                sth = Encoding.ASCII.GetString(data);
 
                //send data
                //string send = textBox2.Text;
                //byte[] sending;
                //sending = Encoding.ASCII.GetBytes(send);
                //textBox2.Text = "";
                //
                //client.Send(sending);
                //
                client.Shutdown(SocketShutdown.Both);
                client.Close();
                
            }
            
        }

and the client side is like this
C#
Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
           IPEndPoint ipend = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8000);
           //soc.Bind(ipend);
           soc.Connect(ipend);
           string input = textBoxX1.Text;
           byte[] data = new byte[500];
           data = Encoding.ASCII.GetBytes(input);
           soc.Send(data);
           string sth = "";
           sth = Encoding.ASCII.GetString(data1);
           textBoxX2.Text = sth;



i think you know what im done. i click the listen button in the server side and the server w'll listen to the line so after i fill the textbox in the client form and click the send button it'll send the data and i can get the data perfectly in the server side
but i need two more things to be done , i want the server do the same thing that the client do that's mean send data to client . and i want the client do the same thing as server that's mean get the data from the server .
i hope you get the idea .
both of them do both sending and receiving at the same time .
how that should be possible ?
AnswerRe: Socket programming Pin
Richard MacCutchan9-Jan-13 4:42
mveRichard MacCutchan9-Jan-13 4:42 
AnswerRe: Socket programming Pin
Pete O'Hanlon9-Jan-13 5:27
mvePete O'Hanlon9-Jan-13 5:27 
AnswerRe: Socket programming Pin
harold aptroot9-Jan-13 6:14
harold aptroot9-Jan-13 6:14 
AnswerRe: Socket programming Pin
Thomas Daniels9-Jan-13 6:47
mentorThomas Daniels9-Jan-13 6:47 
QuestionLooking for a specific regex Pin
Dennis Bork8-Jan-13 21:31
Dennis Bork8-Jan-13 21:31 
AnswerRe: Looking for a specific regex Pin
Pete O'Hanlon8-Jan-13 22:27
mvePete O'Hanlon8-Jan-13 22:27 
AnswerRe: Looking for a specific regex Pin
savbace8-Jan-13 23:49
savbace8-Jan-13 23:49 
AnswerRe: Looking for a specific regex Pin
lmoelleb9-Jan-13 0:12
lmoelleb9-Jan-13 0:12 
GeneralRe: Looking for a specific regex Pin
Dennis Bork9-Jan-13 3:26
Dennis Bork9-Jan-13 3:26 
AnswerRe: Looking for a specific regex Pin
thewazz9-Jan-13 3:38
professionalthewazz9-Jan-13 3:38 
AnswerRe: Looking for a specific regex Pin
PIEBALDconsult9-Jan-13 3:42
mvePIEBALDconsult9-Jan-13 3:42 
QuestionOrder execution sequence Pin
vanikanc8-Jan-13 10:32
vanikanc8-Jan-13 10:32 
AnswerRe: Order execution sequence Pin
YENSIX8-Jan-13 11:17
YENSIX8-Jan-13 11:17 
GeneralRe: Order execution sequence Pin
vanikanc8-Jan-13 14:36
vanikanc8-Jan-13 14:36 
GeneralRe: Order execution sequence Pin
vanikanc9-Jan-13 5:24
vanikanc9-Jan-13 5:24 
GeneralRe: Order execution sequence Pin
Pete O'Hanlon9-Jan-13 5:28
mvePete O'Hanlon9-Jan-13 5:28 
GeneralRe: Order execution sequence Pin
vanikanc9-Jan-13 9:41
vanikanc9-Jan-13 9:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.